package com.pdsu.xpf.graduation01.service.impl;

import com.pdsu.xpf.graduation01.dao.ICommodityDao;
import com.pdsu.xpf.graduation01.domain.Commodity;
import com.pdsu.xpf.graduation01.domain.CommodityType;
import com.pdsu.xpf.graduation01.domain.Type;
import com.pdsu.xpf.graduation01.dto.CommodityLikeDTO;
import com.pdsu.xpf.graduation01.service.ICommodityService;
import com.pdsu.xpf.graduation01.vo.CommodityVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class CommodityServiceImpl implements ICommodityService {

    final
    ICommodityDao commodityDao;

    public CommodityServiceImpl(ICommodityDao commodityDao) {
        this.commodityDao = commodityDao;
    }

    @Override
    public List<Commodity> findAllRecommendCommodity() {
        return commodityDao.findAllRecommendCommodity();
    }

    @Override
    public List<Commodity> findAllCommodity() {
        return commodityDao.findAllCommodity();
    }

    @Override
    public Commodity getCommodityByCID(int cid) {
        return commodityDao.getCommodityByCID(cid);
    }

    @Override
    public List<Commodity> getCommodityByCTID(int ctid) {
        return commodityDao.getCommodityByCTID(ctid);
    }

    @Override
    public List<CommodityLikeDTO> getLikeCommodity(int uid) {
        return commodityDao.getLikeCommodity(uid);
    }

    @Override
    public int addLikeCommodity(int uid, int cid) {
        return commodityDao.addLikeCommodity(uid,cid);
    }

    @Override
    public int delLikeCommodity(int uid, int cid) {
        return commodityDao.delLikeCommodity(uid,cid);
    }

    @Override
    public Integer commodityIsLike(int uid, int cid) {
        return commodityDao.commodityIsLike(uid,cid);
    }

    @Override
    public Integer carIsHaveCommodity(int uid, int cid) {
        return commodityDao.carIsHaveCommodity(uid,cid);
    }

    @Override
        public Integer addCommodityToCar(int uid, int cid) {
        return commodityDao.addCommodityToCar(uid,cid);
    }

    @Override
    public List<Commodity> findCommodityByKey(String key) {
        return commodityDao.findCommodityByKey(key);
    }

    @Override
    public Integer insertACommodity(Commodity commodity) {
        SimpleDateFormat sm= new SimpleDateFormat("yyyy-MM-dd HH:mm");

        String date = sm.format(new Date());
        return commodityDao.insertACommodity(commodity.getUid(),commodity.getCtid(),commodity.getPrice(),commodity.getCnumber(),commodity.getCname(),commodity.getCmessage(),commodity.getUsername(),commodity.getImage(),date);
    }

    @Override
    public List<Type> getAllType() {
        return commodityDao.getAllType();
    }

    @Override
    public List<CommodityType> getCommodityTypeByTID(int tid) {
        return commodityDao.getCommodityTypeByTID(tid);
    }

    @Override
    public List<CommodityVO> findAllCommodityVO() {
        return commodityDao.findAllCommodityVO();
    }

    @Override
    public Integer delCommodityByCID(int cid) {
       return commodityDao.delCommodityByCID(cid);
    }

    @Override
    public List<CommodityVO> findAllCheckCommodityVO() {
        return commodityDao.findAllCheckCommodityVO();
    }

    @Override
    public Integer upCommodityByCID(int cid) {
        return commodityDao.upCommodityByCID(cid);
    }

    @Override
    public List<CommodityVO> searchCommodityByKey(String s) {
        return commodityDao.searchCommodityByKey(s);
    }

    @Override
    public int getCTIDbyTYPENAME(String typename) {
        return commodityDao.getCTIDbyTYPENAME(typename);
    }

    @Override
    public int updateCommodityByCID(int cid, double price, int ctid) {
        return commodityDao.updateCommodityByCID( cid,  price,ctid);
    }


}
